package org.one.afternoon.quartz;

import lombok.extern.slf4j.Slf4j;
import org.one.afternoon.forest.FrontendClient;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@PersistJobDataAfterExecution //持久化
@DisallowConcurrentExecution //禁止并发任务
@Component
@Slf4j
public class SyncJob extends QuartzJobBean {
    @Autowired
    private FrontendClient frontendClient;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        try {
            Thread.sleep(2000);
            SyncJob.log.info(context.getScheduler().getSchedulerInstanceId());
            SyncJob.log.info("taskName:" + context.getJobDetail().getKey().getName());
            SyncJob.log.info("time:" + new Date());
            log.info("HealthJob is running...");
            String formatDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            frontendClient.syncCustomersV2(formatDate);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
